package com.neshai.webapp.component;

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.stereotype.Component;

import java.time.Instant;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

@Component
public class DelayedTask {

    private final ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();

    public DelayedTask() {
        scheduler.initialize();
    }

    public void scheduleDelayedTask() {
        scheduler.schedule(() -> {
            System.out.println("Task executed after delay: " + System.currentTimeMillis());
            //this.scheduleDelayedTask();
        }, Instant.now().plusSeconds(5));  // 延迟 5 秒执行任务
    }

}